<template>
  <j-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    switchFullscreen
    @ok="handleSubmit"
    @cancel="close"
    style="top:50px"
    cancelText="关闭">

    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="编号">
                <a-input placeholder="请输入编号" v-model="queryParam.supplierCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="名称">
                <a-input placeholder="请输入名称" v-model="queryParam.supplierName"></a-input>
              </a-form-item>
            </a-col>
            <!--<template v-if="toggleSearchStatus">
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="状态">
                  <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="erp_status"/>
                </a-form-item>
              </a-col>
            </template>-->
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->
      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
          style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <a-table
          ref="table"
          size="middle"
          :scroll="{x:true}"
          bordered
          :rowKey="(record) => record.id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange , type: checkval}"
          class="j-table-force-nowrap1"
          @change="handleTableChange"/>
      </div>
    </a-card>

  </j-modal>
</template>

<script>
  import Vue from 'vue'
  import { AntDesignOutline, DashboardOutline, TwitterOutline, SearchOutline } from '@ant-design/icons'
  import AntdIcon from '@ant-design/icons-vue'
  import {mixinDevice} from '@/utils/mixin'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import { getAction } from '@api/manage'
  AntdIcon.add(AntDesignOutline, DashboardOutline, SearchOutline)
  Vue.use(AntdIcon)
  import ErpLocationList from '@/views/modules/location/ErpLocationList'


  export default {
    name: 'TslPurchaseSupplier',
    describes: '根据物料选择供应商',
    props: {
      modalWidth: {
        type: Number,
        required: false,
        default: 1200
      },
      value: {
        type: String,
        required: false,
        default: '',
      },
      rowData: {
        type: Object,
        required: false,
      },
      isDisabled: {
        type: Boolean,
        required: false,
        default: false,
      },
      materialId: {
        type: String,
        required: false,
      },
      procurementDetailId: {
        type: String,
      },
      checkval: {
        type: String,
        default: 'radio'
      },
      supplierType: {
        type: Number,
        default: null
      },
    },
    mixins: [mixinDevice, JeecgListMixin],
    components: {
      ErpLocationList,
    },
    data() {
      return {
        visible: false,
        title: '选择供应商',
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'供应商编码',
            align:"center",
            dataIndex: 'supplierCode'
          },
          {
            title:'供应商名称',
            align:"center",
            dataIndex: 'supplierName'
          },
          {
            title:'联系人',
            align:"center",
            dataIndex: 'contact'
          },
          {
            title:'联系电话',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'note'
          },
          {
            title:'创建人',
            align:"center",
            dataIndex: 'createBy_dictText'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime'
          },
        ],
        values: this.value,
        url: {
          list: 'procurement/supplierInformation/list',
          getSupplierByMaterialId: 'procurement/supplierInformation/getSupplierInfosByMaterialId',
          delete: 'procurement/supplierInformation/delete',
          deleteBatch: 'procurement/supplierInformation/deleteBatch',
          exportXlsUrl: 'procurement/supplierInformation/exportXls',
          importExcelUrl: 'procurement/supplierInformation/importExcel',
        },
        dictOptions: {},
        superFieldList: [],
        list1: [],
        options: [],
      }
    },
    created() {
      this.loadData(1);
    },
    mounted() {
      this.$nextTick(() => {
        console.log(this.$refs.location)
        // this.$refs.location.showModal();
      })
    },
    computed: {},
    methods: {
      handleSubmit() {
        console.log("------------submit----------------")
        let selectedRow = null;
        if(this.checkval=='radio'){
          selectedRow = this.selectionRows[0];
        }else{
          selectedRow = this.selectedRowKeys
        }
        // let selectedRow = this.selectionRows[0];
        //传递选中的数据
        console.log("供应商选择",this.selectionRows,selectedRow);
        this.$emit("handleOk", {
          row: this.rowData ? this.rowData.row : '',
          data: selectedRow });

        this.searchReset(false)
        this.onClearSelected();
        this.close();
      },
      searchReset() {
        let categoryNo = this.queryParam.categoryNo;
        this.queryParam = {};
        this.queryParam.categoryNo = categoryNo
        this.loadData(1);
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectionRows = selectionRows
      },
      add() {
        this.showModal()
      },
      showModal() {
        this.visible = true
        this.queryParam = { procurementType: this.procurementType , supplierType: this.supplierType}
        this.loadData(1)
      },
      initDictConfig() {},
      getSuperFieldList() {
        let fieldList = []
        // fieldList.push({type:'string',value:'wareHouseId',text:'仓库',dictCode:"erp_warehouse,name,id"})
        fieldList.push({ type: 'string', value: 'code', text: '库位编号', dictCode: '' })
        fieldList.push({ type: 'string', value: 'name', text: '库位名称', dictCode: '' })
        fieldList.push({ type: 'string', value: 'status', text: '状态', dictCode: 'erp_status' })
        this.superFieldList = fieldList
      },
      handleCancel() {
        this.close()
      },
      handleOk() {
        this.$emit('handlerOk', this.selectionRows[0])
        this.close()
        // console.log(this.selectionRows[0])
      },
      close() {
        // this.searchReset(false);
        this.queryParam = {}
        this.selectedRowKeys = []
        this.selectionRows = []
        this.visible = false
      },
      loadData(arg) {
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件
        this.loading = true;
       /* console.log("11111111111111111111",this.rowData)
        params.materialId = this.rowData.row.materialId
        console.log("22222222222222222",params)*/
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records || res.result;
            this.dataSourceBack=this.dataSource
            if (res.result.total) {
              this.ipagination.total = res.result.total;
            } else {
              this.ipagination.total = 0;
            }
          } else {
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
    },
  }
</script>

<style scoped>
  /* 覆盖Dropdown菜单项在悬停时的背景颜色 */
  .ant-dropdown-menu-item:hover,
  .ant-dropdown-menu-submenu-title:hover {
    background-color: inherit; /* 或者设置为初始背景色 */
  }
</style>